﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WeChatApp.Repositories;
using System.Data;

namespace WeChatApp.Helper.Common
{
    public class BaseHelper
    {
        private static RepositoryFactory _repositoryFactoryInst;
        public static RepositoryFactory RepositoryFactory
        {
            get
            {
                if (_repositoryFactoryInst == null)
                {
                    _repositoryFactoryInst = new RepositoryFactory(RepositoryConst.DefaultConnectString);
                }
                return _repositoryFactoryInst;
            }
        }
        /// <summary>
        /// 生成返回数据
        /// </summary>
        /// <param name="code">返回代码</param>
        /// <param name="msg">返回信息</param>
        /// <param name="count">行数</param>
        /// <param name="dt">数据</param>
        /// <returns></returns>
        public static Dictionary<string, object> MakeDic(string code, string msg, int count, object dt)
        {
            Dictionary<string, object> dic = new Dictionary<string, object>() { };
            dic.Add("code", code);
            dic.Add("msg", msg);
            dic.Add("count", count);
            dic.Add("data", dt);
            return dic;
        }
        /// <summary>
        /// 根据是否有数据返回数据
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static Dictionary<string, object> MakeDicCheck(DataTable dt)
        {
            if (dt.Rows.Count > 0)
                return MakeDic("200", "查询成功", dt.Rows.Count, dt);
            else
                return MakeDic("199", "暂无数据", 0, "");
        }

    }
}
